//
//  FSCObjiectiveCell.swift
//  FamiliesSchoolConnection
//
//  Created by 花花蔡 on 2016/12/31.
//  Copyright © 2016年 com.HuaHuaCai. All rights reserved.
//

import UIKit

class FSCObjiectiveCell: UITableViewCell {

    @IBOutlet weak var qusetionL: UILabel!
    @IBOutlet weak var A: UIButton!
    
    @IBOutlet weak var B: UIButton!
    
    @IBOutlet weak var C: UIButton!
    
    @IBOutlet weak var D: UIButton!
    
    var selectBtn:UIButton?
    
    var callBack:((_ btnTag:Int)->())?
    
    var model:FSCObjectiveModel? {
        didSet {
            let btnAtt = [A,B,C,D]
            for btn in btnAtt {
                btn?.isSelected = false
                
            }
            qusetionL.text = model?.ht_title
           
            for (i,text) in (model?.ht_option ?? []).enumerated() {
                let ho_text = text["ho_text"] as! String
                switch i {
                case 0:
                    A.setTitle(ho_text, for: .normal)
                case 1:
                    B.setTitle(ho_text, for: .normal)
                case 2:
                    C.setTitle(ho_text, for: .normal)
                default:
                    D.setTitle(ho_text, for: .normal)
                }
            }
            for btn in btnAtt {
                if btn?.tag == model?.btnTag {
                    btn?.isSelected = true
                    btn?.setImage(UIImage(named:"选择"), for: .selected)
                }else {
                    btn?.isSelected = false
                }
                
            }

            

            
        }
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

    }
    
    @IBAction func btnClicked(_ sender: UIButton) {
            model?.btnTag = sender.tag
            let btnArr:[UIButton] = [A,B,C,D]

        for btn in btnArr {
            if btn.tag == model?.btnTag {
                btn.isSelected = true
                btn.setImage(UIImage(named:"选择"), for: .selected)
            }else {
                btn.isUserInteractionEnabled = false
            }
            
        }
//
////        selectBtn = sender
////        selectBtn?.isSelected = true
////        selectBtn?.setImage(UIImage(named:"选择"), for: .selected)
//        
//        for item in btnArr {
//            if item.tag == sender.tag {
//                sender.isSelected = true
//                sender.setImage(UIImage(named:"选择"), for: .selected)
//                selectBtn = sender
//            }else {
//                item.isSelected = false
//                item.isUserInteractionEnabled = false
//            }
//            
//            
//        }
//        //        sender.isSelected = true
////        sender.setImage(UIImage(named:"选择"), for: .selected)
//        
   }
    
    
}
